package day11.KeJian;

import java.util.ArrayList;
import java.util.function.Predicate;

public class MyStream3 {
    public static void main(String[] args) {
        //Stream<T> filter(Predicate predicate)：过滤
        //Predicate接口中的方法	boolean test(T t)：对给定的参数进行判断，返回一个布尔值
        ArrayList<String> list = new ArrayList<>();
        list.add("张三丰");
        list.add("张翠山");
        list.add("张无忌");
        list.add("王麻子");
        list.add("张良");
        list.add("谢广坤");

        list.stream().filter(
                new Predicate<String>() {
                    @Override
                    public boolean test(String s) {
                        boolean result = s.startsWith("张");
                        return result; }
                }).forEach(s -> System.out.println(s));
        list.stream().filter(
                (String s)->{
                   boolean result = s.startsWith("张");
                        return result;
                }
        ).forEach(s-> System.out.println(s));

        list.stream().filter(s -> s.startsWith("张")).forEach(s -> System.out.println(s));
    }

}